package com.ruoyi.system.outto.goods.impl;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttrTemplateMapper;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.V2.inter.mapper.SalePartnerMapper;
import com.ruoyi.system.interAttr.domain.InterAttr;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.outto.goods.NEWCYAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.aspectj.weaver.ast.Var;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/8/16 22:58
 */
@Slf4j
@Service
public class NEWCYApiImpl implements NEWCYAPI {
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    InterAttrMapper interAttrMapper;
    @Resource
    private GameAttrTemplateMapper gameAttrTemplateMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    private SalePartnerMapper salePartnerMapper;

    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner);
        log.info("创游添加接口请求参数={}", JSONObject.toJSONString(params));
        Map<String, Object> headers = new HashMap<>();
        headers.put("token", salePartner.getOther());
        Map<String, Object> paramsSin = new HashMap<>();
        paramsSin.put("key", salePartner.getSaleKey());
        paramsSin.put("account", params.get("account"));
        paramsSin.put("account_data", params.get("account_data"));
        paramsSin.put("game_data", params.get("game_data"));
        paramsSin.put("game_id", params.get("game_id"));
        paramsSin.put("img", params.get("img"));
        paramsSin.put("price", params.get("price"));
        paramsSin.put("server_id", params.get("server_id"));
        paramsSin.put("goodsDescribe", params.get("goodsDescribe"));
        String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
        String sign = JSONObject.parseObject(result01).getString("sign");
        Map<String, Object> paramsList = new HashMap<>();
        paramsList.put("account", params.get("account"));
        paramsList.put("account_data", params.get("account_data"));
        paramsList.put("game_data", params.get("game_data"));
        paramsList.put("game_id", params.get("game_id"));
        paramsList.put("img", params.get("img"));
        paramsList.put("price", params.get("price"));
        paramsList.put("server_id", params.get("server_id"));
        paramsList.put("goodsDescribe", params.get("goodsDescribe"));
        paramsList.put("sign", sign);
        String result = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Goods-account-publish", paramsList, headers);
        log.info("创游添加接口返回参数={}", result);
        JSONObject resultJson = JSONObject.parseObject(result);
        if (resultJson.getInteger("code") != 0) {
            result = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Goods-account-publish", paramsList, headers);
            resultJson = JSONObject.parseObject(result);
        }
        if (resultJson.getInteger("code") != 0) {
            resultMap.put("code", 500);
            if ("401".equals(resultJson.getString("code"))) {

                String token = getToken(salePartner);
                salePartner.setOther(token);
                salePartnerMapper.updateSalePartner(salePartner);
            }
        } else {
            resultMap.put("code", 200);
            String data = resultJson.getString("data");
            String goodsId = JSONObject.parseObject(data).getString("goods_id");
            resultMap.put("outId", goodsId);
        }
        resultMap.put("req", JSONObject.toJSONString(params));
        resultMap.put("res", result);
        resultMap.put("msg", resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner);
        log.info("创游添加接口请求参数={}", JSONObject.toJSONString(params));
        Map<String, Object> headers = new HashMap<>();
        headers.put("token", salePartner.getOther());
        Map<String, Object> paramsSin = new HashMap<>();
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        paramsSin.put("id",artRecs.get(0).getOutid());
        paramsSin.put("key", salePartner.getSaleKey());
        paramsSin.put("account", params.get("account"));
        paramsSin.put("account_data", params.get("account_data"));
        paramsSin.put("game_data", params.get("game_data"));
        paramsSin.put("game_id", params.get("game_id"));
        paramsSin.put("img", params.get("img"));
        paramsSin.put("price", params.get("price"));
        paramsSin.put("server_id", params.get("server_id"));
        paramsSin.put("goodsDescribe", params.get("goodsDescribe"));
        String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
        String sign = JSONObject.parseObject(result01).getString("sign");
        Map<String, Object> paramsList = new HashMap<>();
        paramsList.put("id",artRecs.get(0).getOutid());
        paramsList.put("account", params.get("account"));
        paramsList.put("account_data", params.get("account_data"));
        paramsList.put("game_data", params.get("game_data"));
        paramsList.put("game_id", params.get("game_id"));
        paramsList.put("img", params.get("img"));
        paramsList.put("price", params.get("price"));
        paramsList.put("server_id", params.get("server_id"));
        paramsList.put("goodsDescribe", params.get("goodsDescribe"));
        paramsList.put("sign", sign);
        String result = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Goods-account-edit", paramsList, headers);
        log.info("创游添加接口返回参数={}", result);
        JSONObject resultJson = JSONObject.parseObject(result);
        if (resultJson.getInteger("code") != 0) {
            result = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Goods-account-edit", paramsList, headers);
            resultJson = JSONObject.parseObject(result);
        }
        if (resultJson.getInteger("code") != 0) {
            resultMap.put("code", 500);
            if ("401".equals(resultJson.getString("code"))) {

                String token = getToken(salePartner);
                salePartner.setOther(token);
                salePartnerMapper.updateSalePartner(salePartner);
            }
        } else {
            resultMap.put("code", 200);
        }
        resultMap.put("req", JSONObject.toJSONString(params));
        resultMap.put("res", result);
        resultMap.put("msg", resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> header = new HashMap<>();
        header.put("token",salePartner.getOther());
        Map<String, Object> params = new HashMap<>();
        Map<String, Object> paramsSin = new HashMap<>();
        String substring = salePartner.getSaleName().substring(salePartner.getSaleName().indexOf("_")+1);
        InterAttr interAttr = interAttrMapper.selectInterAttrByConfig(substring, goodsInfoAndAttrValueDto.getGameId());
        params.put("game_id",interAttr.getInterGameId());
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        params.put("id",artRecs.get(0).getOutid());
        params.put("status","CLOSE");

        paramsSin.put("key", salePartner.getSaleKey());
        paramsSin.put("game_id",interAttr.getInterGameId());
        paramsSin.put("id",artRecs.get(0).getOutid());
        paramsSin.put("status","CLOSE");
        String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, header);
        String sign = JSONObject.parseObject(result01).getString("sign");
        params.put("sign",sign);
        log.info("创游删除接口请求参数={}", JSONObject.toJSONString(params));
        String result = HttpRequest.post("https://w1.cy227.com/docking/Goods-account-listedOrUnlisted")
                .header("token", salePartner.getOther())
                .body(JSONObject.toJSONString(params)).execute().body();
        log.info("创游删除接口返回参数={}", result);
        JSONObject resultJson = JSONObject.parseObject(result);
        if(Objects.nonNull(resultJson)) {
            if (resultJson.getInteger("code") != 0) {
                resultMap.put("code", 500);
                if ("401".equals(resultJson.getString("code"))) {

                    String token = getToken(salePartner);
                    salePartner.setOther(token);
                    salePartnerMapper.updateSalePartner(salePartner);
                }
            } else {
                resultMap.put("code", 200);
            }
        }else{
            resultMap.put("code", 500);
        }
        resultMap.put("req", JSONObject.toJSONString(params));
        resultMap.put("res", result);
        resultMap.put("msg", resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }
    /**
     * 开始匹配区服属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param params
     * @param server
     */
    private void builderServer(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String server) {
        //========================开始匹配区服属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(server);
        //开始匹配一级区服
        String interServeReqs = jsonObject.getString("interServeReqs");
        String qufuid = "";
        JSONObject oneServerJson = new JSONObject();
        List<JSONObject> oneServer = JSONObject.parseArray(interServeReqs, JSONObject.class);
        String gameClientId = "";
        String gameServerId = "";
        if (Objects.equals(goodsInfoAndAttrValueDto.getGameType(), "0")) {
            qufuid = goodsInfoAndAttrValueDto.getSystemId() + ""+goodsInfoAndAttrValueDto.getCarrierId() + "";
            if(goodsInfoAndAttrValueDto.getGameName().equals("三角洲行动")) {
                qufuid = goodsInfoAndAttrValueDto.getSystemId() + "";
            }
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                ydServeId = ydServeId.replace(" ","").replace(",","");
                if(ydServeId.equals(qufuid)){
                    gameClientId = object.getString("id");
                    qufuid = goodsInfoAndAttrValueDto.getSystemId()+""+goodsInfoAndAttrValueDto.getCarrierId() + "";
                    if(goodsInfoAndAttrValueDto.getGameName().equals("永劫无间手游")) {
                        qufuid = goodsInfoAndAttrValueDto.getCarrierId() + "";
                    }else if(goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟(手游)")) {
                        qufuid = goodsInfoAndAttrValueDto.getSystemId() + ""+goodsInfoAndAttrValueDto.getCarrierId() + "";
                    }else if(goodsInfoAndAttrValueDto.getGameName().equals("使命召唤手游")) {
                        qufuid = goodsInfoAndAttrValueDto.getCarrierId() + "";
                    }else if(goodsInfoAndAttrValueDto.getGameName().equals("王者荣耀")) {
                        qufuid = goodsInfoAndAttrValueDto.getSystemId() + ""+goodsInfoAndAttrValueDto.getCarrierId() + "";
                    }else if(goodsInfoAndAttrValueDto.getGameName().equals("三角洲行动")) {
                        qufuid = goodsInfoAndAttrValueDto.getSystemId() + "";
                    }
                    String interServerRes = object.getString("interServerRes");
                    if(StringUtils.isNotEmpty(interServerRes)) {
                        oneServer = JSONObject.parseArray(interServerRes, JSONObject.class);
                        for (JSONObject objects : oneServer) {
                            String ydServeIds = objects.getString("YdServeId");
                            if (StringUtils.isNotEmpty(ydServeIds)) {
                                ydServeIds = ydServeIds.replace(",", "").replace(" ", "");
                                if (ydServeIds.contains(qufuid)) {
                                    gameServerId = objects.getString("id");
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("无畏契约")){
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (ydServeId.contains(qufuid)) {
                        gameClientId = object.getString("id");
                        String interServerRes = object.getString("interServerRes");
                        qufuid = goodsInfoAndAttrValueDto.getGroupId()+"";
                        oneServer = JSONObject.parseArray(interServerRes, JSONObject.class);
                        for(JSONObject objects : oneServer){
                            String ydServeIds = objects.getString("YdServeId");
                            ydServeIds = ydServeIds.replace(",", "").replace(" ", "");
                            if (Objects.equals(qufuid, ydServeIds)) {
                                gameServerId = objects.getString("id");
                                break;
                            }
                        }
                    }
                }
            }
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟")){
            qufuid = goodsInfoAndAttrValueDto.getServerId()+"";
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (ydServeId.contains(qufuid)) {
                        gameClientId = object.getString("id");
                        break;
                    }
                }
            }
        }
        else {
            qufuid = goodsInfoAndAttrValueDto.getGroupId()+"";;
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (Objects.equals(qufuid, ydServeId)) {
                        gameClientId = object.getString("id");
                        String interServerRes = object.getString("interServerRes");
                        qufuid = goodsInfoAndAttrValueDto.getServerId()+"";
                        oneServer = JSONObject.parseArray(interServerRes, JSONObject.class);
                        for(JSONObject objects : oneServer){
                            String ydServeIds = objects.getString("YdServeId");
                            ydServeIds = ydServeIds.replace(",", "").replace(" ", "");
                            if (ydServeIds.contains(qufuid)) {
                                gameServerId = objects.getString("id");
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (Objects.isNull(oneServerJson)) {
            throw new GlobalException("运营商未匹配到");
        }
        params.put("server_id", gameClientId);
       // params.put("gameServerId", gameServerId);
    }


    /**
     * 开始匹配单选属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param radioAttr
     */
    private void builderRadioAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, String radioAttr, List<Object> gameData) {
        //========================开始匹配单选属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(radioAttr);
        String interRadioReqs = jsonObject.getString("interRadioReqs");
        log.info(JSONObject.toJSONString(interRadioReqs));
        List<JSONObject> jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
        if (!org.springframework.util.CollectionUtils.isEmpty(jsonObjects)) {
            /**
             * 1、先查询自定义中所有单选的字段
             * 2、再查该账号单选字段中的选项
             * 3、再去接口属性匹配表过滤
             */
            GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
            gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
            gameAttrTemplate.setIsEnable("0");
            gameAttrTemplate.setFieldType("radio");
            List<GameAttrTemplate> gameAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
            Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();


            List<JSONObject> defObjects = new ArrayList<>();
            defObjects.addAll(jsonObjects);
            for (JSONObject object : jsonObjects) {
                if(object.getString("id").equals("该游戏没有该匹配项 保存即可！")){
                    return;
                }
                String string = "";
                for (GameAttrTemplate attrTemplate : gameAttrTemplates) {
                    String aavName = attrTemplate.getAavName();
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (aavName.equals(name)) {
                            //一级属性
                            //注意 YdConfigId 对应的是 f字段对应的 id
                            if (Objects.equals(object.getLong("YdConfigId"), attrTemplate.getId())) {
                                String InterConfigId = object.getString("InterConfigId");
                                defObjects.remove(object);//如果匹配上，则去掉
                                String interRadioReqs1 = object.getString("interRadioReqs");
                                List<JSONObject> jsonObjects2 = JSONObject.parseArray(interRadioReqs1, JSONObject.class);
                                declaredField.setAccessible(true);
                                try {
                                    //获取选择的值 例如  实名中的可二次
                                    Object o = declaredField.get(goodsInfoAndAttrValueDto);
                                    String oneValue = String.valueOf(o);
                                    List<JSONObject> twoAttr = jsonObjects2.stream().filter(j -> Objects.equals(j.getString("YdConfigId"), oneValue)).collect(Collectors.toList());
                                    String defaultValue = object.getString("defaultValue");
                                    if (org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                        if (StringUtils.isNotEmpty(defaultValue)) {
                                            String interServerRes = object.getString("interServerRes");
                                            List<JSONObject> interServerResss = JSONObject.parseArray(interServerRes, JSONObject.class);
                                            for(JSONObject jsonObject1 : interServerResss) {
                                                string = jsonObject1.getString("id")+"-"+jsonObject1.getString("name");
                                                gameData.add(string);
                                            }
                                        }
                                    }
                                    if (!org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                        JSONObject jsonObject2 = twoAttr.get(0);
                                        string = jsonObject2.getString("id")+"-"+jsonObject2.getString("name");
                                        gameData.add(string);
                                    }
                                } catch (Exception e) {
                                    throw new GlobalException("单选项" + attrTemplate.getFieldName() + "匹配错误");
                                }
                            }
                        }
                    }
                }
            }
            //开始匹配默认值
            for (JSONObject object : defObjects) {
                interRadioReqs = object.getString("interRadioReqs");
                jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
                String string = "";
                for (JSONObject objects : jsonObjects) {
                    if(StringUtils.isNotEmpty(objects.getString("defaultValue"))){
                        string = objects.getString("id")+"-"+objects.getString("name");
                        gameData.add(string);
                    }
                }
            }
            //========================单选属性匹配结束=====================//
        }
    }

    /**
     * 开始匹配多选属性
     *
     * @param goodsInfoAndAttrValueDto
     */
    private void builderCheckAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, String checkAttr,List<Object> gameData) {

        //========================开始匹配多选属性=====================//
        /**
         * 1、先查询自定义中所有多选的字段
         * 2、再查该账号单选字段中的选项
         * 3、再去接口属性匹配表过滤
         */
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();
        JSONObject checkAttrJson = JSONObject.parseObject(checkAttr);
        String interCheckBoxReqs = checkAttrJson.getString("interCheckBoxReqs");
        List<JSONObject> checkJsonList = JSONObject.parseArray(interCheckBoxReqs, JSONObject.class);
        if (org.springframework.util.CollectionUtils.isEmpty(checkAttrJson)) {
            throw new GlobalException("接口多选属性暂未配置");
        }

        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        List<String> types = new ArrayList<>();
        types.add("checkbox");
        types.add("boxradio");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> checkAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);

        for (JSONObject object : checkJsonList) {
            String string = "";
            for (GameAttrTemplate attrTemplate : checkAttrTemplates) {
                String aavName = attrTemplate.getAavName();
                for (Field declaredField : declaredFields) {
                    String name = declaredField.getName();
                    if (aavName.equals(name)) {
                        declaredField.setAccessible(true);

                        String ydConfigIdLeveOne = object.getString("YdConfigId");
                        if (StringUtils.isNotEmpty(ydConfigIdLeveOne)) {

                            String[] split2 = ydConfigIdLeveOne.split(",");
                            List<String> list2 = new ArrayList<>();
                            for (String s : split2) {
                                s = s.replace(" ", "");
                                list2.add(s);
                            }
                            if (list2.contains(attrTemplate.getId() + "")) {
                                Object o = null;
                                try {
                                    o = declaredField.get(goodsInfoAndAttrValueDto);
                                } catch (IllegalAccessException e) {
                                    throw new GlobalException("多选项" + attrTemplate.getFieldName() + "匹配错误");
                                }
                                String oneValue = String.valueOf(o);
                                //一级属性
                                String ydConfigId = object.getString("YdConfigId");
                                String InterConfigName = object.getString("InterConfigName");
                                String InterConfigId = object.getString("InterConfigId");
                                if (StringUtils.isNotEmpty(ydConfigId)) {
                                    ydConfigId = ydConfigId.replace(" ","");
                                    String[] split = ydConfigId.split(",");
                                    //一级属性已经匹配，开始匹配二级属性
                                    if (Arrays.asList(split).contains(attrTemplate.getId() + "")) {
                                        String interCheckBoxReqsStr = object.getString("interCheckBoxReqs");
//                                        String interCheckBoxReqsStr = object.getString("interServerRes");
                                        //开始匹配二级属性
                                        List<JSONObject> jsonObjects2 = JSONObject.parseArray(interCheckBoxReqsStr, JSONObject.class);
                                        /**
                                         * 咱们的f字段  多选项都是用空格 隔开，用,号切割数组，跟匹配的数据匹配、匹配上说明此账号勾选的有此属性
                                         */
//                                        List<String> list = new ArrayList<>();
                                        for (JSONObject jsonObject1 : jsonObjects2) {
                                             if (StringUtils.isNotEmpty(oneValue)) {
                                                String[] split1 = oneValue.split(",");
                                                String ydConfigId1 = jsonObject1.getString("YdConfigId");
                                                for (String s : split1) {
                                                    if (Objects.equals(s, ydConfigId1)) {
                                                        string += jsonObject1.getString("id")+"-"+jsonObject1.getString("name");
                                                        gameData.add(jsonObject1.getString("id")+"-"+jsonObject1.getString("name"));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    throw new GlobalException("属性参数错误，请匹配后重新配置");
                                }
                            }
                        }
                    }
                }
            }
//            if(StringUtils.isNotEmpty(string)) {
//                gameData.add(string);
//            }
        }
        //========================多选属性匹配完成=====================//
    }

    /**
     * 开始匹配输入框属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param inputAttr
     */
    private void builderInputAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, String inputAttr, List<Object> gameData) {
//        JSONArray propertys = Objects.isNull(params.get("property")) ? new JSONArray() : JSONArray.parseArray(params.get("property").toString());
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();

        //========================开始匹配输入框=====================//
        JSONObject jsonObject1 = JSONObject.parseObject(inputAttr);
        String inputJson = jsonObject1.getString("inputJson");
        List<JSONObject> jsonObjects1 = JSONObject.parseArray(inputJson, JSONObject.class);
        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        ArrayList types = new ArrayList<>();
        types.add("number");
        types.add("input");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> inputTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
        List<JSONObject> defInputObjects = new ArrayList<>();
        defInputObjects.addAll(jsonObjects1);
        for (JSONObject object : jsonObjects1) {
            if(object.getString("id").equals("该游戏没有该匹配项 保存即可！")){
                return;
            }
            for (GameAttrTemplate inputTemplate : inputTemplates) {
                String string = "";
                String aavName = inputTemplate.getAavName();
                if (Objects.equals(object.getString("aavName"), inputTemplate.getAavName())) {
                    defInputObjects.remove(object);
                    String aavNameInter = object.getString("interName");
                    String interId = object.getString("interId");
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (Objects.equals(aavName, name)) {
                            declaredField.setAccessible(true);
                            Object o = null;
                            try {
                                o = declaredField.get(goodsInfoAndAttrValueDto);
                            } catch (IllegalAccessException e) {
                                throw new GlobalException("3属性参数错误，请匹配后重新配置");
                            }
                            String oneValue = String.valueOf(o);
                            if (StringUtils.isNotEmpty(oneValue)) {
                                string = object.getString("id")+"-"+oneValue;
                                gameData.add(string);
                            }
                        }
                    }
                }
            }
        }
        //开始匹配默认值
        for (JSONObject object : defInputObjects) {
            String string = "";
            String id = object.getString("id");
            String defaultValue = object.getString("defaultValue");
            if (StringUtils.isNotEmpty(defaultValue)) {
                string = id+"-"+0;
//                gameData.add(string);
            }
        }
    }

    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> params = new TreeMap<>();
        //自动匹配属性
        String substring = salePartner.getSaleName().substring(salePartner.getSaleName().indexOf("_")+1);
        InterAttr interAttr = interAttrMapper.selectInterAttrByConfig(substring, goodsInfoAndAttrValueDto.getGameId());
        params.put("game_id",interAttr.getInterGameId());
        List<Object> accountData = new ArrayList<>();
        List<Object> gameData = new ArrayList<>();


        params.put("goodsDescribe", goodsInfoAndAttrValueDto.getDes());
        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
        String imgUrls = infoImgs.stream().map(info -> info.getImgUrl()).collect(Collectors.toList()).stream().collect(Collectors.joining(","));
        params.put("img", goodsInfoAndAttrValueDto.getTitleImg()+","+imgUrls);
        params.put("price", goodsInfoAndAttrValueDto.getPrice());
        params.put("account", goodsInfoAndAttrValueDto.getAccountNumber());

        //开始匹配区服属性
        if(!goodsInfoAndAttrValueDto.getGameName().equals("无畏契约")&&!goodsInfoAndAttrValueDto.getGameName().equals("金铲铲之战")) {
            builderServer(goodsInfoAndAttrValueDto, params, interAttr.getServer());
        }
        //开始匹配单选属性
        builderRadioAttr(goodsInfoAndAttrValueDto,interAttr.getRadioAttr(),gameData);
        //开始匹配多选属性
        builderCheckAttr(goodsInfoAndAttrValueDto,interAttr.getCheckAttr(),gameData);
        //开始匹配输入框属性
        builderInputAttr(goodsInfoAndAttrValueDto,interAttr.getInputAttr(),gameData);



        if(goodsInfoAndAttrValueDto.getGameName().equals("王者荣耀")){
            params.put("game_id", "12");
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            JSONArray jsonArray1 = JSONArray.parseArray(data1);
            for (Object o : jsonArray1) {
                if (JSONObject.parseObject(o.toString()).getString("name").contains("王者营地号")) {
                    accountData.add("104" + "-" + goodsInfoAndAttrValueDto.getF17());
                }
                if (JSONObject.parseObject(o.toString()).getString("name").equals("账号来源")) {
                    accountData.add("157-一手号");
                }
                GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
                if (JSONObject.parseObject(o.toString()).getString("name").equals("实名情况")) {
                    if (gameAttribute.getFieldName().equals("可二次实名")) {
                        accountData.add("510-" + "可二次实名");
                    } else if (gameAttribute.getFieldName().equals("不可二次实名")) {
                        accountData.add("511-" + "不可二次实名");
                    } else if (gameAttribute.getFieldName().equals("已删除实名")) {
                        accountData.add("511-" + "已删除实名");
                    } else if (gameAttribute.getFieldName().equals("包人脸")) {
                        accountData.add("513-" + "包人脸");
                    } else {
                        accountData.add("");
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("name").equals("系统")) {
                    if (goodsInfoAndAttrValueDto.getSystemName().contains("安卓")) {
                        accountData.add("507-安卓");
                    } else if (gameAttribute.getFieldName().equals("IOS") || gameAttribute.getFieldName().equals("苹果")) {
                        accountData.add("508-IOS");
                    } else {
                        accountData.add("");
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("name").equals("账号绑定")) {
                    accountData.add("518-无绑定");
                }
            }
        }
        else if (goodsInfoAndAttrValueDto.getGameName().equals("和平精英")) {
            params.put("game_id", "22");
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            JSONArray jsonArray1 = JSONArray.parseArray(data1);
            for (Object o : jsonArray1) {
                if (JSONObject.parseObject(o.toString()).getString("name").equals("实名情况")) {
                    GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
                    if (gameAttribute.getFieldName().equals("可二次实名")) {
                        accountData.add("771-" + "可二次");
                    } else if (gameAttribute.getFieldName().equals("不可二次实名")) {
                        accountData.add("772-" + "不可二次");
                    } else if (gameAttribute.getFieldName().equals("已删除实名")) {
                        accountData.add("773-" + "已删实名");
                    } else if (gameAttribute.getFieldName().equals("包人脸")) {
                        accountData.add("774-" + "包人脸");
                    } else {
                        accountData.add("");
                    }
                }
                if (JSONObject.parseObject(o.toString()).getString("name").contains("和平营地号")) {
                    accountData.add("105" + "-" + goodsInfoAndAttrValueDto.getF13());
                }
                if (JSONObject.parseObject(o.toString()).getString("name").equals("账号来源")) {
                    accountData.add("190-一手号");
                }
            }
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("穿越火线")){
            params.put("game_id", "23");
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
//            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
//            String data1 = JSONObject.parseObject(options).getString("data");
            GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
            if (gameAttribute.getFieldName().equals("有修改机会且实名是本人")) {
                accountData.add("1054-" + "可二次");
            } else {
                accountData.add("1055-" + "不可二次包人脸");
            }
            accountData.add("196-" + "一手号");
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("枪战王者")){
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
            if (gameAttribute.getFieldName().equals("可修改实名")) {
                accountData.add("505-" + "有二次");
            } else {
                accountData.add("504-" + "包人脸");
            }
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF9())) {
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF9()));
                if(gameAttribute1.getFieldName().equals("不可转区")) {
                    accountData.add("501-不支持转区");
                }else {
                    accountData.add("501-支持转区");
                }
            }
            accountData.add("247-一手号");
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟")){
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
            if (gameAttribute.getFieldName().equals("可修改实名")) {
                accountData.add("581-" + "是");
            } else {
                accountData.add("582-" + "否");
            }
            accountData.add("578-可换或未绑");
            accountData.add("199-一手号");
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("英雄联盟(手游)")){
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF4()));
            if (gameAttribute.getFieldName().equals("可修改实名")) {
                accountData.add("584-" + "是");
            } else {
                accountData.add("585-" + "否");
            }
            accountData.add("587-未绑定或可换");
            accountData.add("203-一手号");
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("金铲铲之战")){
            params.put("server_id", "3008");
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
            if (gameAttribute.getFieldName().equals("可修改实名")) {
                accountData.add("618-" + "是");
            } else {
                accountData.add("619-" + "否");
            }
            String regional = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            if(regional.equals("安卓QQ")){
                accountData.add("613-" + goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName());
            }else if(regional.equals("安卓微信")){
                accountData.add("614-" + goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName());
            }else if(regional.equals("苹果QQ")){
                accountData.add("615-" + goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName());
            }else {
                accountData.add("616-" + goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName());
            }
            accountData.add("187-一手号");
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("三角洲行动")){
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF7()));
            if (gameAttribute.getFieldName().equals("可修改实名")) {
                accountData.add("1059-" + "可二次实名");
            } else {
                accountData.add("1060-" + "不可二次实名");
            }
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("原神")){
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            GameAttribute gameAttribute=  gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
            if (gameAttribute.getFieldName().equals("可修改实名")) {
                accountData.add("505-" + "有二次");
            } else {
                accountData.add("504-" + "包人脸");
            }
            accountData.add("501-支持转区");
            accountData.add("247-一手号");
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("使命召唤手游")){
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            accountData.add("297-一手号");
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("永劫无间")){
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            accountData.add("504-" + "包人脸");
            accountData.add("501-支持转区");
            accountData.add("247-一手号");
        }
        else if(goodsInfoAndAttrValueDto.getGameName().equals("永劫无间手游")){
            Map<String, Object> headers = new HashMap<>();
            headers.put("token", salePartner.getOther());
            Map<String, Object> paramsSin = new HashMap<>();
            paramsSin.put("key", salePartner.getSaleKey());
            paramsSin.put("game_id", params.get("game_id"));
            String result01 = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
            String sign = JSONObject.parseObject(result01).getString("sign");
            Map<String, Object> paramsList = new HashMap<>();
            paramsList.put("game_id", params.get("game_id"));
            paramsList.put("sign", sign);
            String options = HttpUtils.doPostFormData("https://w1.cy227.com/docking/Game-account-data", paramsList, headers);
            String data1 = JSONObject.parseObject(options).getString("data");
            accountData.add("504-" + "包人脸");
            accountData.add("501-支持转区");
            accountData.add("247-一手号");
        }

        try {
            String accountData1 = getAccountData(params.get("game_id").toString(), salePartner);
            String data = JSONObject.parseObject(accountData1).getString("data");
            JSONArray array = JSONArray.parseArray(data);
            for (Object o : array) {
                if (JSONObject.parseObject(o.toString()).getString("fieldName").equals("是否靓号")) {
                    String options = JSONObject.parseObject(o.toString()).getString("options");
                    JSONArray array1 = JSONArray.parseArray(options);
                    for (Object p : array1) {
                        if (JSONObject.parseObject(p.toString()).getString("fieldName").equals("是")) {
                            accountData.add(JSONObject.parseObject(p.toString()).getString("id") + "-" + JSONObject.parseObject(p.toString()).getString("fieldName"));
                            break;
                        }
                    }
                }
            }
        }catch (Exception e){}

        params.put("account_data", JSONObject.toJSONString(accountData));
        params.put("game_data", JSONObject.toJSONString(gameData));
        return params;
    }


    public static void main(String[] args) {

        Map<String, Object> headers = new HashMap<>();
        headers.put("token", "4a90d578-c56c4cafbb8f2516-848d16c7-267bd67d-579af226c344");
        Map<String, Object> paramsSin = new HashMap<>();
        paramsSin.put("key", "LGJpvKiMfzo58Wh0lSy6rEkbH4wtO7Tc");
        paramsSin.put("game_id", 38);
        String result01 = HttpUtils.doPostFormData("http://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
        String sign = JSONObject.parseObject(result01).getString("sign");
        Map<String, Object> paramsList = new HashMap<>();
        paramsList.put("game_id", 38);
        paramsList.put("sign", sign);
        String options = HttpUtils.doPostFormData("http://w1.cy227.com/docking/Game-account-data", paramsList, headers);
        System.out.println(options);
    }

    String getAccountData(String game_id,SalePartner salePartner){
        Map<String, Object> headers = new HashMap<>();
        headers.put("token", salePartner.getOther());
        Map<String, Object> paramsSin = new HashMap<>();
        paramsSin.put("key", salePartner.getSaleKey());
        paramsSin.put("game_id", game_id);
        String result01 = HttpUtils.doPostFormData("http://w1.cy227.com/docking/Get-Sign", paramsSin, headers);
        String sign = JSONObject.parseObject(result01).getString("sign");
        Map<String, Object> paramsList = new HashMap<>();
        paramsList.put("game_id", game_id);
        paramsList.put("sign", sign);
        String options = HttpUtils.doPostFormData("http://w1.cy227.com/docking/Game-account-data", paramsList, headers);
        return options;
    }

    String getGbr(){
        String url = "https://yihao.yihaoyou.com/bapi/goods/getGames";
        Map<String,Object> params = new TreeMap<>();
        params.put("timestamp",System.currentTimeMillis()/1000);
        String cover = "";
        cover = cover+"key=UFA4K5PO97&"+"timestamp="+params.get("timestamp");
        System.out.println(cover);
        String sign = DigestUtils.md5Hex(cover).toUpperCase();
        params.put("api_key","U0029");
        params.put("sign",sign);
        System.out.println(sign);
//        String string = HttpUtils.doPostFormData(url, params, null);
        String string = HttpRequest.post(url).body(JSONObject.toJSONString(params)).execute().body();
        return string;
    }

    public static String getToken(SalePartner salePartner) {
        Map<String, String> params = new HashMap<>();
        params.put("account", salePartner.getTwoOther());
        params.put("password", salePartner.getThreeOther());
        String result = HttpUtils.doPostForm("https://w1.cy227.com/docking/User-GetToken", params, null);
        String data = JSONObject.parseObject(result).getString("data");
        String token = JSONObject.parseObject(data).getString("token");
        return token;
    }

    public static String getGames() {
        Map<String, String> params = new HashMap<>();
//        params.put("account", "18224436134");
//        params.put("password", "182244asdf");
        String result = HttpUtils.doPostForm("https://cy227.com/api/web/v1/publics/game/getGameInfoList", params, null);
        return result;
    }
}
